/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.db.DbMailItem;
/*     */ import com.zimbra.cs.db.DbResults;
/*     */ import com.zimbra.cs.db.DbUtil;
/*     */ import com.zimbra.cs.index.SortBy;
/*     */ import com.zimbra.cs.index.ZimbraQueryResults;
/*     */ import com.zimbra.cs.mailbox.Conversation;
/*     */ import com.zimbra.cs.mailbox.Flag;
/*     */ import com.zimbra.cs.mailbox.Flag.FlagInfo;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.Folder.FolderOptions;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxIndex;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.Tag;
/*     */ import java.util.EnumSet;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestUnread
/*     */   extends TestCase
/*     */ {
/*     */   private Mailbox mMbox;
/*     */   private Account mAccount;
/*  48 */   private static String USER_NAME = "user1";
/*  49 */   private static String TEST_NAME = "TestUnread";
/*     */   
/*  51 */   private static String FOLDER1_NAME = TEST_NAME + " Folder 1";
/*  52 */   private static String FOLDER2_NAME = TEST_NAME + " Folder 2";
/*  53 */   private static String TAG1_NAME = TEST_NAME + " Tag 1";
/*  54 */   private static String TAG2_NAME = TEST_NAME + " Tag 2";
/*  55 */   private static String TAG3_NAME = TEST_NAME + " Tag 3";
/*     */   
/*     */   private int mMessage1Id;
/*     */   
/*     */   private int mMessage2Id;
/*     */   
/*     */   private int mMessage3Id;
/*     */   
/*     */   private int mFolder1Id;
/*     */   
/*     */   private int mFolder2Id;
/*     */   private int mTag1Id;
/*     */   private int mTag2Id;
/*     */   private int mTag3Id;
/*     */   private int mConvId;
/*     */   
/*     */   public TestUnread(String testName)
/*     */   {
/*  73 */     super(testName);
/*     */   }
/*     */   
/*  76 */   private Message getMessage1() throws Exception { return this.mMbox.getMessageById(null, this.mMessage1Id); }
/*  77 */   private Message getMessage2() throws Exception { return this.mMbox.getMessageById(null, this.mMessage2Id); }
/*  78 */   private Message getMessage3() throws Exception { return this.mMbox.getMessageById(null, this.mMessage3Id); }
/*  79 */   private Conversation getConv() throws Exception { return this.mMbox.getConversationById(null, this.mConvId); }
/*  80 */   private Folder getFolder1() throws Exception { return this.mMbox.getFolderById(null, this.mFolder1Id); }
/*  81 */   private Folder getFolder2() throws Exception { return this.mMbox.getFolderById(null, this.mFolder2Id); }
/*  82 */   private Tag getTag1() throws Exception { return this.mMbox.getTagById(null, this.mTag1Id); }
/*  83 */   private Tag getTag2() throws Exception { return this.mMbox.getTagById(null, this.mTag2Id); }
/*  84 */   private Tag getTag3() throws Exception { return this.mMbox.getTagById(null, this.mTag3Id); }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected void setUp()
/*     */     throws Exception
/*     */   {
/*  97 */     super.setUp();
/*     */     
/*  99 */     this.mAccount = TestUtil.getAccount(USER_NAME);
/* 100 */     this.mMbox = MailboxManager.getInstance().getMailboxByAccount(this.mAccount);
/*     */     
/*     */ 
/* 103 */     TestUtil.deleteTestData(USER_NAME, TEST_NAME);
/*     */     
/* 105 */     Message msg = TestUtil.addMessage(this.mMbox, TEST_NAME);
/* 106 */     this.mMessage1Id = msg.getId();
/* 107 */     ZimbraLog.test.debug("Created message 1, id=" + this.mMessage1Id);
/*     */     
/* 109 */     msg = TestUtil.addMessage(this.mMbox, "RE: " + TEST_NAME);
/* 110 */     this.mMessage2Id = msg.getId();
/* 111 */     ZimbraLog.test.debug("Created message 2, id=" + this.mMessage2Id);
/*     */     
/* 113 */     msg = TestUtil.addMessage(this.mMbox, "RE: " + TEST_NAME);
/* 114 */     this.mMessage3Id = msg.getId();
/* 115 */     ZimbraLog.test.debug("Created message 3, id=" + this.mMessage3Id);
/*     */     
/* 117 */     this.mConvId = getMessage1().getConversationId();
/* 118 */     ZimbraLog.test.debug("Created conversation, id=" + this.mConvId);
/*     */     
/* 120 */     Folder folder = this.mMbox.createFolder(null, FOLDER1_NAME, 2, new Folder.FolderOptions());
/* 121 */     this.mFolder1Id = folder.getId();
/*     */     
/* 123 */     folder = this.mMbox.createFolder(null, FOLDER2_NAME, this.mFolder1Id, new Folder.FolderOptions());
/* 124 */     this.mFolder2Id = folder.getId();
/*     */     
/* 126 */     Tag tag = this.mMbox.createTag(null, TAG1_NAME, (byte)0);
/* 127 */     this.mTag1Id = tag.getId();
/*     */     
/* 129 */     tag = this.mMbox.createTag(null, TAG2_NAME, (byte)0);
/* 130 */     this.mTag2Id = tag.getId();
/*     */     
/* 132 */     tag = this.mMbox.createTag(null, TAG3_NAME, (byte)0);
/* 133 */     this.mTag3Id = tag.getId();
/*     */     
/* 135 */     this.mMbox.move(null, this.mMessage1Id, getMessage1().getType(), this.mFolder1Id);
/* 136 */     this.mMbox.move(null, this.mMessage2Id, getMessage1().getType(), this.mFolder2Id);
/* 137 */     this.mMbox.move(null, this.mMessage3Id, getMessage1().getType(), this.mFolder2Id);
/* 138 */     this.mMbox.alterTag(null, this.mMessage1Id, getMessage1().getType(), getTag1().getName(), true, null);
/* 139 */     this.mMbox.alterTag(null, this.mMessage1Id, getMessage1().getType(), getTag2().getName(), true, null);
/* 140 */     this.mMbox.alterTag(null, this.mMessage2Id, getMessage2().getType(), getTag2().getName(), true, null);
/*     */   }
/*     */   
/*     */   public void testReadMessage1() throws Exception
/*     */   {
/* 145 */     ZimbraLog.test.debug("testReadMessage1");
/* 146 */     verifySetUp();
/* 147 */     setUnread(getMessage1(), false);
/* 148 */     verifyMessage1Read();
/*     */   }
/*     */   
/*     */   public void testReadMessage2() throws Exception
/*     */   {
/* 153 */     ZimbraLog.test.debug("testReadMessage2");
/* 154 */     verifySetUp();
/*     */     
/* 156 */     setUnread(getMessage2(), false);
/*     */     
/* 158 */     assertEquals("getMessage1().getUnreadCount()", 1, getMessage1().getUnreadCount());
/* 159 */     assertEquals("getMessage2().getUnreadCount()", 0, getMessage2().getUnreadCount());
/* 160 */     assertEquals("getMessage3().getUnreadCount()", 1, getMessage3().getUnreadCount());
/* 161 */     assertEquals("getConv().getUnreadCount()", 2, getConv().getUnreadCount());
/* 162 */     assertEquals("getFolder1().getUnreadCount()", 1, getFolder1().getUnreadCount());
/* 163 */     assertEquals("getFolder2().getUnreadCount()", 1, getFolder2().getUnreadCount());
/* 164 */     assertEquals("getTag1().getUnreadCount()", 1, getTag1().getUnreadCount());
/* 165 */     assertEquals("getTag2().getUnreadCount()", 1, getTag2().getUnreadCount());
/* 166 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */     
/* 168 */     verifyAllUnreadFlags();
/*     */   }
/*     */   
/*     */   public void testReadAllMessages() throws Exception
/*     */   {
/* 173 */     ZimbraLog.test.debug("testReadAllMessages");
/* 174 */     verifySetUp();
/*     */     
/* 176 */     setUnread(getMessage1(), false);
/* 177 */     setUnread(getMessage2(), false);
/* 178 */     setUnread(getMessage3(), false);
/* 179 */     verifyAllRead();
/*     */   }
/*     */   
/*     */   public void testReadConversation() throws Exception
/*     */   {
/* 184 */     ZimbraLog.test.debug("testReadConversation");
/* 185 */     setUnread(getConv(), false);
/* 186 */     verifyAllRead();
/*     */   }
/*     */   
/*     */   public void testReadFolder1() throws Exception
/*     */   {
/* 191 */     ZimbraLog.test.debug("testReadFolder1");
/* 192 */     verifySetUp();
/* 193 */     setUnread(getFolder1(), false);
/* 194 */     verifyMessage1Read();
/*     */   }
/*     */   
/*     */   public void testReadFolder2() throws Exception
/*     */   {
/* 199 */     ZimbraLog.test.debug("testReadFolder2");
/* 200 */     verifySetUp();
/*     */     
/* 202 */     setUnread(getFolder2(), false);
/*     */     
/* 204 */     assertEquals("getMessage1().getUnreadCount()", 1, getMessage1().getUnreadCount());
/* 205 */     assertEquals("getMessage2().getUnreadCount()", 0, getMessage2().getUnreadCount());
/* 206 */     assertEquals("getMessage3().getUnreadCount()", 0, getMessage3().getUnreadCount());
/* 207 */     assertEquals("getConv().getUnreadCount()", 1, getConv().getUnreadCount());
/* 208 */     assertEquals("getFolder1().getUnreadCount()", 1, getFolder1().getUnreadCount());
/* 209 */     assertEquals("getFolder2().getUnreadCount()", 0, getFolder2().getUnreadCount());
/* 210 */     assertEquals("getTag1().getUnreadCount()", 1, getTag1().getUnreadCount());
/* 211 */     assertEquals("getTag2().getUnreadCount()", 1, getTag2().getUnreadCount());
/* 212 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */   }
/*     */   
/*     */   public void testReadAllFolders() throws Exception
/*     */   {
/* 217 */     ZimbraLog.test.debug("testReadAllMessages");
/* 218 */     verifySetUp();
/*     */     
/* 220 */     setUnread(getFolder1(), false);
/* 221 */     setUnread(getFolder2(), false);
/* 222 */     verifyAllRead();
/*     */   }
/*     */   
/*     */   public void testReadTag1() throws Exception
/*     */   {
/* 227 */     ZimbraLog.test.debug("testReadTag1");
/* 228 */     verifySetUp();
/* 229 */     setUnread(getTag1(), false);
/* 230 */     verifyMessage1Read();
/*     */   }
/*     */   
/*     */   public void testReadTag2() throws Exception
/*     */   {
/* 235 */     ZimbraLog.test.debug("testReadTag2");
/* 236 */     verifySetUp();
/*     */     
/* 238 */     setUnread(getTag2(), false);
/*     */     
/* 240 */     assertEquals("getMessage1().getUnreadCount()", 0, getMessage1().getUnreadCount());
/* 241 */     assertEquals("getMessage2().getUnreadCount()", 0, getMessage2().getUnreadCount());
/* 242 */     assertEquals("getMessage3().getUnreadCount()", 1, getMessage3().getUnreadCount());
/* 243 */     assertEquals("getConv().getUnreadCount()", 1, getConv().getUnreadCount());
/* 244 */     assertEquals("getFolder1().getUnreadCount()", 0, getFolder1().getUnreadCount());
/* 245 */     assertEquals("getFolder2().getUnreadCount()", 1, getFolder2().getUnreadCount());
/* 246 */     assertEquals("getTag1().getUnreadCount()", 0, getTag1().getUnreadCount());
/* 247 */     assertEquals("getTag2().getUnreadCount()", 0, getTag2().getUnreadCount());
/* 248 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */     
/* 250 */     verifyAllUnreadFlags();
/*     */   }
/*     */   
/*     */   public void testMoveMessage() throws Exception
/*     */   {
/* 255 */     ZimbraLog.test.debug("testMoveMessage");
/* 256 */     verifySetUp();
/*     */     
/*     */ 
/* 259 */     this.mMbox.move(null, this.mMessage2Id, getMessage2().getType(), this.mFolder1Id);
/* 260 */     assertEquals("getMessage2().getUnreadCount()", 1, getMessage2().getUnreadCount());
/* 261 */     assertEquals("getFolder1().getUnreadCount()", 2, getFolder1().getUnreadCount());
/* 262 */     assertEquals("getFolder2().getUnreadCount()", 1, getFolder2().getUnreadCount());
/*     */     
/*     */ 
/* 265 */     setUnread(getMessage2(), false);
/* 266 */     assertEquals("getMessage2().getUnreadCount()", 0, getMessage2().getUnreadCount());
/* 267 */     assertEquals("getFolder1().getUnreadCount()", 1, getFolder1().getUnreadCount());
/* 268 */     assertEquals("getFolder2().getUnreadCount()", 1, getFolder2().getUnreadCount());
/*     */     
/*     */ 
/* 271 */     this.mMbox.move(null, this.mMessage2Id, getMessage2().getType(), this.mFolder2Id);
/* 272 */     assertEquals("getMessage2().getUnreadCount()", 0, getMessage2().getUnreadCount());
/* 273 */     assertEquals("getFolder1().getUnreadCount()", 1, getFolder1().getUnreadCount());
/* 274 */     assertEquals("getFolder2().getUnreadCount()", 1, getFolder2().getUnreadCount());
/*     */   }
/*     */   
/*     */   public void testMoveConversation() throws Exception
/*     */   {
/* 279 */     ZimbraLog.test.debug("testMoveConversation");
/* 280 */     verifySetUp();
/*     */     
/*     */ 
/* 283 */     setUnread(getMessage1(), false);
/* 284 */     this.mMbox.move(null, getConv().getId(), getConv().getType(), this.mFolder1Id);
/* 285 */     assertEquals("getMessage1().getUnreadCount()", 0, getMessage1().getUnreadCount());
/* 286 */     assertEquals("getMessage2().getUnreadCount()", 1, getMessage2().getUnreadCount());
/* 287 */     assertEquals("getMessage3().getUnreadCount()", 1, getMessage3().getUnreadCount());
/* 288 */     assertEquals("getConv().getUnreadCount()", 2, getConv().getUnreadCount());
/* 289 */     assertEquals("getFolder1().getUnreadCount()", 2, getFolder1().getUnreadCount());
/* 290 */     assertEquals("getFolder2().getUnreadCount()", 0, getFolder2().getUnreadCount());
/*     */     
/*     */ 
/* 293 */     this.mMbox.move(null, getConv().getId(), getConv().getType(), this.mFolder2Id);
/* 294 */     assertEquals("getMessage1().getUnreadCount()", 0, getMessage1().getUnreadCount());
/* 295 */     assertEquals("getMessage2().getUnreadCount()", 1, getMessage2().getUnreadCount());
/* 296 */     assertEquals("getMessage3().getUnreadCount()", 1, getMessage3().getUnreadCount());
/* 297 */     assertEquals("getConv().getUnreadCount()", 2, getConv().getUnreadCount());
/* 298 */     assertEquals("getFolder1().getUnreadCount()", 0, getFolder1().getUnreadCount());
/* 299 */     assertEquals("getFolder2().getUnreadCount()", 2, getFolder2().getUnreadCount());
/*     */   }
/*     */   
/*     */   public void testTagMessage() throws Exception
/*     */   {
/* 304 */     ZimbraLog.test.debug("testTagMessage");
/* 305 */     verifySetUp();
/*     */     
/*     */ 
/* 308 */     this.mMbox.alterTag(null, this.mMessage3Id, getMessage3().getType(), getTag3().getName(), true, null);
/* 309 */     assertEquals("getTag3().getUnreadCount()", 1, getTag3().getUnreadCount());
/*     */     
/*     */ 
/* 312 */     this.mMbox.alterTag(null, this.mMessage2Id, getMessage2().getType(), getTag3().getName(), true, null);
/* 313 */     assertEquals("getTag3().getUnreadCount()", 2, getTag3().getUnreadCount());
/*     */     
/*     */ 
/* 316 */     this.mMbox.alterTag(null, this.mMessage3Id, getMessage3().getType(), getTag3().getName(), false, null);
/* 317 */     assertEquals("getTag3().getUnreadCount()", 1, getTag3().getUnreadCount());
/*     */   }
/*     */   
/*     */   public void testTagConversation() throws Exception
/*     */   {
/* 322 */     ZimbraLog.test.debug("testTagConversation");
/* 323 */     verifySetUp();
/*     */     
/*     */ 
/* 326 */     this.mMbox.alterTag(null, getConv().getId(), getConv().getType(), getTag3().getName(), true, null);
/* 327 */     assertEquals("getTag3().getUnreadCount()", 3, getTag3().getUnreadCount());
/*     */     
/*     */ 
/* 330 */     this.mMbox.alterTag(null, getConv().getId(), getConv().getType(), getTag3().getName(), false, null);
/* 331 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testMoveToTrash()
/*     */     throws Exception
/*     */   {
/* 339 */     ZimbraLog.test.debug("testMoveToTrash");
/* 340 */     verifySetUp();
/*     */     
/* 342 */     Folder inbox = this.mMbox.getFolderById(null, 2);
/* 343 */     int unreadCount = inbox.getUnreadCount();
/*     */     
/*     */ 
/* 346 */     this.mMbox.move(null, getConv().getId(), getConv().getType(), 2);
/* 347 */     assertEquals("Move conversation to inbox", unreadCount + 3, inbox.getUnreadCount());
/*     */     
/*     */ 
/* 350 */     setUnread(getMessage2(), false);
/* 351 */     assertEquals("Read message 2", unreadCount + 2, inbox.getUnreadCount());
/*     */     
/*     */ 
/* 354 */     this.mMbox.move(null, this.mMessage1Id, getMessage1().getType(), 3);
/* 355 */     assertEquals("Move message to trash", unreadCount + 1, inbox.getUnreadCount());
/*     */     
/*     */ 
/* 358 */     this.mMbox.move(null, getConv().getId(), getConv().getType(), 3);
/* 359 */     assertEquals("Move conversation to trash", unreadCount, inbox.getUnreadCount());
/*     */   }
/*     */   
/*     */ 
/*     */   public void testSearch()
/*     */     throws Exception
/*     */   {
/* 366 */     ZimbraLog.test.debug("testSearch");
/* 367 */     verifySetUp();
/*     */     
/* 369 */     ZimbraQueryResults results = this.mMbox.index.search(new OperationContext(this.mMbox), "is:unread", EnumSet.of(MailItem.Type.MESSAGE), SortBy.DATE_DESC, 100);
/*     */     
/* 371 */     assertTrue("No search results found", results.hasNext());
/* 372 */     results.close();
/*     */   }
/*     */   
/*     */   public void testDeleteConversation() throws Exception
/*     */   {
/* 377 */     ZimbraLog.test.debug("testDeleteConversation");
/* 378 */     verifySetUp();
/*     */     
/* 380 */     this.mMbox.delete(null, getConv().getId(), getConv().getType());
/*     */     
/* 382 */     assertEquals("getFolder1().getUnreadCount()", 0, getFolder1().getUnreadCount());
/* 383 */     assertEquals("getFolder2().getUnreadCount()", 0, getFolder2().getUnreadCount());
/* 384 */     assertEquals("getTag1().getUnreadCount()", 0, getTag1().getUnreadCount());
/* 385 */     assertEquals("getTag2().getUnreadCount()", 0, getTag2().getUnreadCount());
/* 386 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */   }
/*     */   
/*     */   public void testDeleteFolder2() throws Exception
/*     */   {
/* 391 */     ZimbraLog.test.debug("testDeleteFolder2");
/* 392 */     verifySetUp();
/*     */     
/* 394 */     this.mMbox.delete(null, this.mFolder2Id, getFolder2().getType());
/*     */     
/* 396 */     assertEquals("getMessage1().getUnreadCount()", 1, getMessage1().getUnreadCount());
/* 397 */     assertEquals("getConv().getUnreadCount()", 1, getConv().getUnreadCount());
/* 398 */     assertEquals("getFolder1().getUnreadCount()", 1, getFolder1().getUnreadCount());
/* 399 */     assertEquals("getTag1().getUnreadCount()", 1, getTag1().getUnreadCount());
/* 400 */     assertEquals("getTag2().getUnreadCount()", 1, getTag2().getUnreadCount());
/* 401 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */   }
/*     */   
/*     */   public void testDeleteFolder1() throws Exception
/*     */   {
/* 406 */     ZimbraLog.test.debug("testDeleteFolder1");
/* 407 */     verifySetUp();
/*     */     
/* 409 */     this.mMbox.delete(null, this.mFolder1Id, getFolder1().getType());
/*     */     
/* 411 */     assertEquals("getTag1().getUnreadCount()", 0, getTag1().getUnreadCount());
/* 412 */     assertEquals("getTag2().getUnreadCount()", 0, getTag2().getUnreadCount());
/* 413 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */   }
/*     */   
/*     */   private void verifyMessage1Read() throws Exception
/*     */   {
/* 418 */     assertEquals("getMessage1().getUnreadCount()", 0, getMessage1().getUnreadCount());
/* 419 */     assertEquals("getMessage2().getUnreadCount()", 1, getMessage2().getUnreadCount());
/* 420 */     assertEquals("getMessage3().getUnreadCount()", 1, getMessage3().getUnreadCount());
/* 421 */     assertEquals("getConv().getUnreadCount()", 2, getConv().getUnreadCount());
/* 422 */     assertEquals("getFolder1().getUnreadCount()", 0, getFolder1().getUnreadCount());
/* 423 */     assertEquals("getFolder2().getUnreadCount()", 2, getFolder2().getUnreadCount());
/* 424 */     assertEquals("getTag1().getUnreadCount()", 0, getTag1().getUnreadCount());
/* 425 */     assertEquals("getTag2().getUnreadCount()", 1, getTag2().getUnreadCount());
/* 426 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */     
/* 428 */     verifyAllUnreadFlags();
/*     */   }
/*     */   
/*     */   private void verifyAllUnreadFlags() throws Exception
/*     */   {
/* 433 */     verifyUnreadFlag(getMessage1());
/* 434 */     verifyUnreadFlag(getMessage2());
/* 435 */     verifyUnreadFlag(getMessage3());
/* 436 */     verifyUnreadFlag(getConv());
/* 437 */     verifyUnreadFlag(getFolder1());
/* 438 */     verifyUnreadFlag(getFolder2());
/* 439 */     verifyUnreadFlag(getTag1());
/* 440 */     verifyUnreadFlag(getTag2());
/*     */     
/*     */ 
/* 443 */     DbResults results = DbUtil.executeQuery("SELECT COUNT(*) FROM " + DbMailItem.getMailItemTableName(this.mMbox) + " WHERE mailbox_id = " + this.mMbox.getId() + " AND flags & " + Flag.BITMASK_UNREAD + " > 0", new Object[0]);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 448 */     int numRows = results.getInt(1);
/* 449 */     assertEquals("Found " + numRows + " items with old unread flag set", 0, numRows);
/*     */   }
/*     */   
/*     */   private void verifyUnreadFlag(MailItem item) throws Exception {
/* 453 */     String flagString = item.getFlagString();
/* 454 */     if (item.isUnread()) {
/* 455 */       assertTrue("unread bit test: " + item.getFlagBitmask(), (item.getFlagBitmask() & Flag.BITMASK_UNREAD) > 0);
/* 456 */       assertTrue("unread flag string: " + flagString, flagString.indexOf(Flag.toChar(Flag.ID_UNREAD)) >= 0);
/*     */     } else {
/* 458 */       assertTrue("read bit test: " + item.getFlagBitmask(), (item.getFlagBitmask() & Flag.BITMASK_UNREAD) == 0);
/* 459 */       assertTrue("read flag string: " + flagString, flagString.indexOf(Flag.toChar(Flag.ID_UNREAD)) == -1);
/*     */     }
/*     */     
/*     */ 
/* 463 */     if (item.getType() == MailItem.Type.MESSAGE) {
/* 464 */       DbResults results = DbUtil.executeQuery("SELECT unread FROM " + DbMailItem.getMailItemTableName(item) + " WHERE mailbox_id = " + item.getMailboxId() + " AND id = " + item.getId(), new Object[0]);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 469 */       assertEquals("Verify unread flag in the database", item.isUnread(), results.getBoolean(1));
/*     */     }
/*     */   }
/*     */   
/*     */   private void verifyAllRead() throws Exception
/*     */   {
/* 475 */     assertEquals("getMessage1().getUnreadCount()", 0, getMessage1().getUnreadCount());
/* 476 */     assertEquals("getMessage2().getUnreadCount()", 0, getMessage2().getUnreadCount());
/* 477 */     assertEquals("getMessage3().getUnreadCount()", 0, getMessage3().getUnreadCount());
/* 478 */     assertEquals("getConv().getUnreadCount()", 0, getConv().getUnreadCount());
/* 479 */     assertEquals("getFolder1().getUnreadCount()", 0, getFolder1().getUnreadCount());
/* 480 */     assertEquals("getFolder2().getUnreadCount()", 0, getFolder2().getUnreadCount());
/* 481 */     assertEquals("getTag1().getUnreadCount()", 0, getTag1().getUnreadCount());
/* 482 */     assertEquals("getTag2().getUnreadCount()", 0, getTag2().getUnreadCount());
/* 483 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */     
/* 485 */     verifyAllUnreadFlags();
/*     */   }
/*     */   
/*     */   private void setUnread(MailItem item, boolean unread) throws Exception {
/* 489 */     this.mMbox.alterTag(null, item.getId(), item.getType(), Flag.FlagInfo.UNREAD, unread, null);
/* 490 */     item = this.mMbox.getItemById(null, item.getId(), item.getType());
/* 491 */     verifyUnreadFlag(item);
/*     */   }
/*     */   
/*     */   private void verifySetUp() throws Exception
/*     */   {
/* 496 */     assertEquals("getMessage1().getUnreadCount()", 1, getMessage1().getUnreadCount());
/* 497 */     assertEquals("getMessage2().getUnreadCount()", 1, getMessage2().getUnreadCount());
/* 498 */     assertEquals("getMessage3().getUnreadCount()", 1, getMessage3().getUnreadCount());
/* 499 */     assertEquals("getConv().getUnreadCount()", 3, getConv().getUnreadCount());
/* 500 */     assertEquals("getFolder1().getUnreadCount()", 1, getFolder1().getUnreadCount());
/* 501 */     assertEquals("getFolder2().getUnreadCount()", 2, getFolder2().getUnreadCount());
/* 502 */     assertEquals("getTag1().getUnreadCount()", 1, getTag1().getUnreadCount());
/* 503 */     assertEquals("getTag2().getUnreadCount()", 2, getTag2().getUnreadCount());
/* 504 */     assertEquals("getTag3().getUnreadCount()", 0, getTag3().getUnreadCount());
/*     */     
/* 506 */     assertEquals("getMessage1().getFolderId()", this.mFolder1Id, getMessage1().getFolderId());
/* 507 */     assertEquals("getMessage2().getFolderId()", this.mFolder2Id, getMessage2().getFolderId());
/* 508 */     assertEquals("getMessage3().getFolderId()", this.mFolder2Id, getMessage3().getFolderId());
/*     */     
/* 510 */     assertTrue("getMessage1().isTagged(getTag1())", getMessage1().isTagged(getTag1()));
/* 511 */     assertTrue("getMessage1().isTagged(getTag2())", getMessage1().isTagged(getTag2()));
/* 512 */     assertTrue("getMessage2().isTagged(getTag2())", getMessage2().isTagged(getTag2()));
/*     */   }
/*     */   
/*     */   protected void tearDown() throws Exception
/*     */   {
/* 517 */     TestUtil.deleteTestData(USER_NAME, TEST_NAME);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestUnread.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */